//
//  YTCameraCell.m
//  YUNT
//
//  Created by 梁炜东 on 2017/11/20.
//  Copyright © 2017年 梁炜东. All rights reserved.
//

#import "YTCameraCell.h"
#import "YTSetUtils.h"
@interface YTCameraCell ()
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UILabel *subLabel;
@property(nonatomic, strong)YTSetUtils *utilsView;
@end

@implementation YTCameraCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.backgroundColor = [UIColor clearColor];
        [self p_addSubViews];
        [self p_makeConstraints];
    }
    return self;
}
-(void)p_addSubViews
{
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.textColor = [UIColor whiteColor];
    _titleLabel.font = [UIFont systemFontOfSize:17];
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_titleLabel];
    
    _subLabel = [[UILabel alloc] init];
    _subLabel.textColor = [UIColor whiteColor];
    _subLabel.font = [UIFont systemFontOfSize:15];
    _subLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:_subLabel];
    
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = YTColorAlpha(180, 180, 180, 0.3);
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.equalTo(self);
        make.height.mas_equalTo(1);
    }];
}
-(void)p_makeConstraints
{
    [_titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self).offset(10);
        make.top.bottom.trailing.equalTo(self);
    }];
    [_subLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self).offset(-30);
        make.leading.top.bottom.equalTo(self);
    }];
}
-(void)configObject:(NSArray *)arr
{
    [_utilsView removeFromSuperview];
    _utilsView = nil;
    _utilsView = [[YTSetUtils alloc] init];
    [self addSubview:_utilsView];
    _titleLabel.text = arr[_indexPath.row];
    NSArray *sources = nil;
    if (_indexPath.section == 0)
    {
        switch (_indexPath.row)
        {
            case 0:
                sources = @[@"MOV", @"MP4"];
                [_utilsView showWithTexts:sources block:^(NSInteger tag, UIButton *sender) {
                }];
                _subLabel.hidden = YES;
                break;
            case 1:
                sources = @[@"PAL", @"NTSC"];
                [_utilsView showWithTexts:sources block:^(NSInteger tag, UIButton *sender) {
                    
                }];
                _subLabel.hidden = YES;
                break;
            default:
                break;
        }
    }else if (_indexPath.section == 1)
    {
        switch (_indexPath.row)
        {
            case 0:
                sources = @[@"4:3", @"16:9"];
                [_utilsView showWithTexts:sources block:^(NSInteger tag, UIButton *sender) {
                    
                }];
                _subLabel.hidden = YES;
                break;
            case 1:
                _utilsView.hidden = YES;
                _subLabel.hidden = NO;;
                _subLabel.text = Language(@"视频");
                break;
            default:
                break;
        }
    }else if (_indexPath.section == 2)
    {
        _subLabel.hidden = YES;
        switch (_indexPath.row)
        {
            case 0:
                sources = @[@"Auto", @"50Hz", @"60Hz"];
                [_utilsView showWithTexts:sources block:^(NSInteger tag, UIButton *sender) {
                }];
                break;
            case 1:
                sources = @[@"复位", @"连续"];
                [_utilsView showWithTexts:sources block:^(NSInteger tag, UIButton *sender) {
                    
                }];
                break;
            case 2:
                sources = @[@"恢复"];
                [_utilsView showWithTexts:sources block:^(NSInteger tag, UIButton *sender) {
                    sender.selected = NO;
                    sender.backgroundColor = [UIColor clearColor];
                }];
                break;
            default:
                break;
        }
    }
    [_utilsView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self).offset(-10);
        make.centerY.equalTo(self);
        make.height.mas_equalTo(50);
        make.width.mas_equalTo(70*sources.count);
    }];
}
@end
